use serde::Deserialize;
mod linear_delay_retire;
mod tools;

pub use linear_delay_retire::LinearDelayPolicy;

pub trait RetirePolicy {
    /// 获取退休结果.
    fn get_retire_result(&self, msg: PersonMessage) -> anyhow::Result<RetireResult>;
}

/// 想加东西也不是不行喵.
#[derive(Debug, Clone, Deserialize, Eq, PartialEq, Hash)]
pub enum Gender {
    #[serde(rename = "男")]
    Male,
    #[serde(rename = "女")]
    Female,
}

impl Gender {
    /// 把字符串翻译成`Gender`.
    pub fn string_to_gender(s: &str) -> Option<Gender> {
        let gender = match s {
            "男" => Gender::Male,
            "女" => Gender::Female,
            _ => return None,
        };
        Some(gender)
    }
}

/// 人员退休相关信息.
/// 允许不提供某些信息.
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PersonMessage {
    /// year-month
    pub birth_time: (u32, u32),
    pub prev_retire_age: Option<u32>,
    pub gender: Option<Gender>,
}

/// 退休结果, 即退休时间、退休年龄和延迟退休月数.
#[derive(Debug, Clone)]
pub struct RetireResult {
    /// year-month
    pub retire_time: (u32, u32),
    pub retire_age: f32,
    /// 负数能表示提早退休
    pub delayed_retire_months: i32,
}
